package com.songtech.server.Point;

import com.songtech.server.celltrack.model.CellTrack;
import com.songtech.server.constant.Calculate;
import com.songtech.server.entry.PositionProtocal;

/**
 * Create By YINN on 2018/4/28 18:20
 * Description :
 */
public class PosPoint {

    private double lon;

    private double lat;

    private Double speed;

    private Integer direction;

    private PosPoint(double lon, double lat) {
        this.lon = lon;
        this.lat = lat;
    }

    private PosPoint(double lon, double lat, Double speed, Integer direction) {
        this.lon = lon;
        this.lat = lat;
        this.speed = speed;
        this.direction = direction;
    }

    /**
     * @param protocal 携带数值的协议实体类
     * @return PosPoint
     * @Description : 点位实例构造工厂
     */
    public static PosPoint instanceFactory(PositionProtocal protocal) {

        Double speed = protocal.getSpeed() == null ? null : Double.valueOf((protocal.getSpeed() / Calculate.SPEED_FACTOR));

        Integer direction = protocal.getDirection() == null ? null : protocal.getDirection();

        return new PosPoint(protocal.getLongitude() / Calculate.LON_LAT_FACTOR, protocal.getLatitude() / Calculate.LON_LAT_FACTOR,
                speed, direction);
    }

    /**
     * @param cellTrack 携带数值的协议实体类
     * @return PosPoint
     * @Description : 点位实例构造工厂
     */
    public static PosPoint instanceFactory(CellTrack cellTrack){

        return new PosPoint(cellTrack.getLongitude().doubleValue(),cellTrack.getLatitude().doubleValue());

    }

    /**
     * @return PosPoint
     * @Description : 点位实例构造工厂
     */
    public static PosPoint instanceFactory(double lon, double lat) {
        return new PosPoint(lon, lat);
    }

    public double getLon() {
        return lon;
    }

    public double getLat() {
        return lat;
    }

    public Double getSpeed() {
        return speed;
    }

    public Integer getDirection() {
        return direction;
    }
}
